<template>
    <div>
        <el-button @click="showDialog('insert')" class="slot-btn-top" type="primary" size="small">新增App包</el-button>
        <el-table :data="dataList" stripe border :height="tableHeight" :header-cell-style="getRowClass" v-loading='loading'>
            <el-table-column fixed type="index" label="*"  min-width="40"></el-table-column>
            <el-table-column prop="name" label="名称"  min-width="100"></el-table-column>
            <el-table-column prop="creatorName" label="创建人"  min-width="90"></el-table-column>
            <el-table-column prop="createTime" label="创建时间"  min-width="140"></el-table-column>
            <el-table-column fixed="right" label="操作"  align="right" width="200">
                <template slot-scope="scope">
                    <el-button @click="download(scope.row)" type="text" size="mini">下载</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
        <el-dialog :title="dialog.title" width="600" top="30px" :visible.sync="dialog.isShow" :close-on-click-modal="false" v-dialogDrag>
            <el-form :model="dialog.formData" class="demo-form-inline">
                <el-form-item label="名称">
                    <el-input v-model="dialog.formData.name" placeholder="请输入名称" class="width220"></el-input>
                </el-form-item>
                <el-form-item label="安装包">
                    <el-upload
                        class="upload-demo"
                        :action="uploadApi"
                        :on-success="handleAvatarSuccess"
                        multiple
                        :limit="1">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传apk文件</div>
                    </el-upload>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">提交</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
import postSaleApi from '@/axios/postSale.js'
import baseHttp from '@/axios/baseHttp.js'
export default {
    name: '',
    data() {
      return {
            tableHeight:document.documentElement.clientHeight - 140,
            loading:false,
            uploadApi:baseHttp.publicImgLoad(),
            dataList:[],
            dialog:{
                title:'新增app包',
                isShow:false,
                formData:{}
            },
            pagination:{
                currentPage:1,
                pageSize:10,
                total:0
            },
      }
    },
    mounted(){
        this.getDatalist();
    },
    methods:{
        showDialog(){
            this.dialog.isShow=true;

        },
        getDatalist(){
            let self = this;
            let data = {
                currentPage:self.pagination.currentPage,
                pageSize:self.pagination.pageSize
            }
            self.loading = true;
            postSaleApi.appList(data).then(res=>{
               self.dataList=res.content.records;
               self.pagination.total = res.content.total;
                self.loading = false;
            },error=>{
                self.loading = false;
            })
        },
        handleAvatarSuccess(res, file){
            console.log(res)
            this.dialog.formData.path=res.content
        },
        onSubmit(){
            let self = this;

            postSaleApi.insertApp(self.dialog.formData).then(res=>{
                self.$message.success(`${self.dialog.title}成功`);
                 self.getDatalist();
                 self.dialog.isShow = false;
            })
        },
        handleSizeChange(size){
            let self = this;
            self.pagination.pageSize=size;
             self.getDatalist();
        },
        handleCurrentChange(current){
            let self = this;
            self.pagination.currentPage=current;
            self.getDatalist();
        },
        download(row){
            window.location.href = row.path;
        }
    }
  }
</script>
<style scoped>
</style>
